package com.ztesoft.report.controller;

import com.ztesoft.report.dao.ServiceInterfaceDao;
import com.ztesoft.report.entity.Dashboard;
import com.ztesoft.report.entity.ServiceInterface;
import com.ztesoft.report.service.ServiceInterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author :xie
 * Email: 1487471733@qq.com
 * Date: 2018/6/21
 * Time: 15:45
 * Describe:
 */
@RestController
@RequestMapping("/dashboard")
public class DashboardController {

    @Autowired
    private ServiceInterfaceService serviceInterfaceService;
    @Autowired
    private ServiceInterfaceDao serviceInterfaceDao;



    @RequestMapping("")
    public List<ServiceInterface> serviceInterfaceList(){

        return serviceInterfaceService.selectList(null);
    }

    @RequestMapping("/dashboard")
    public List<Dashboard> index(){

        List<Dashboard> listDashboard= serviceInterfaceDao.listDashboard();
        for (Dashboard dashboard:listDashboard){
            if (dashboard.getStatus().equals("00W")){
                dashboard.setMsg("等待生成");
            }
            if (dashboard.getStatus().equals("00F")){
                dashboard.setMsg("文件上传");
            }
            if (dashboard.getStatus().equals("00E")){
                dashboard.setMsg("等待上传");
            }
            if (dashboard.getStatus().equals("00D")){
                dashboard.setMsg("数据生成");
            }
        }

        return  listDashboard;

    }
    @RequestMapping("/time")
    public  List<Dashboard> time(@RequestParam(required = false)String createtime,@RequestParam(required = false)String updatetime){
         List<Dashboard> dashboards = serviceInterfaceDao.listErrOrSue(createtime, updatetime);
         if(dashboards.size()!=0&&dashboards!=null) {
             for (Dashboard dashboard : dashboards) {
                 if (dashboard.getStatus().equals("00A")) {
                     dashboard.setMsg("成功");
                 }
                 if (dashboard.getStatus().equals("00X")) {
                     dashboard.setMsg("失败");
                 }

             }
         }
        return dashboards;
    }

    @RequestMapping("/lines")
    public Map<String,Object> listDashboardByLines(){

        return serviceInterfaceDao.listDashboardByLines();
    }

}
